package com.example.qimo

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView

import com.example.qimo.weather.Forecast

class ForecastAdapter(private val context: Context, private val forecastList: List<Forecast>) : BaseAdapter() {

    private val inflater: LayoutInflater = LayoutInflater.from(context)

    override fun getCount(): Int = forecastList.size

    override fun getItem(position: Int): Any = forecastList[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val view = convertView ?: inflater.inflate(R.layout.list_item_forecast, parent, false)
        val forecast = forecastList[position]

        val dateTextView = view.findViewById<TextView>(R.id.textView_date)
        val highTextView = view.findViewById<TextView>(R.id.textView_high)
        val lowTextView = view.findViewById<TextView>(R.id.textView_low)
        val typeTextView = view.findViewById<TextView>(R.id.textView_type)

        dateTextView.text = forecast.date
        highTextView.text = "High: ${forecast.high}"
        lowTextView.text = "Low: ${forecast.low}"
        typeTextView.text = forecast.type

        return view
    }
}